unit paramchangesframeunit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, StdCtrls, ExtCtrls, Spin, fpjson,
  database, languagehelper, controlhelper;

type

  { TParamChangesFrame }

  TParamChangesFrame = class(TFrame)
    ParamChangesFlowPanel: TFlowPanel;
    ParameterChangesGroupBox: TGroupBox;
  private
    Db: TDatabase;
    EditedParams: TJSONArray;
    ParamPanels: TParamPanels;

    procedure CreateParamPanels;
  public
    procedure SetDatabase(ADb: TDatabase);
    procedure SetEditedParams(AParams: TJSONArray);
    procedure UpdateLanguage(Code: String);
    destructor Destroy; override;
  end;

implementation

{$R *.lfm}

{ TParamChangesFrame }

procedure TParamChangesFrame.CreateParamPanels;
var
  I: Integer;
begin
  ParamPanels := TParamPanels.Create(Self, ParamChangesFlowPanel, Db);

  for I := 2 to 7 do
    ParamPanels.CreatePanel(I);
  { Max. HP and Max. MP are displayed last on this screen, because they are
   rarely changed }
  ParamPanels.CreatePanel(0);
  ParamPanels.CreatePanel(1);
end;

procedure TParamChangesFrame.SetDatabase(ADb: TDatabase);
begin
  Db := ADb;
  CreateParamPanels;
  ParameterChangesGroupBox.AutoSize := True;
end;

procedure TParamChangesFrame.SetEditedParams(AParams: TJSONArray);
var
  I: Integer;
begin
  EditedParams := AParams;
  ParamPanels.SetParams(EditedParams);
end;

procedure TParamChangesFrame.UpdateLanguage(Code: String);
begin
  if IsLanguageRtl(Code) then begin
    ParamChangesFlowPanel.FlowStyle := fsRightLeftTopBottom;
  end else begin
    ParamChangesFlowPanel.FlowStyle := fsLeftRightTopBottom;
  end;
end;

destructor TParamChangesFrame.Destroy;
begin
  inherited Destroy;
  if ParamPanels <> nil then
    ParamPanels.Free;
end;

end.

